﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using welding.Model;

namespace welding
{
    public class Production
    {
        private string v;

        public Production(string v)
        {
            this.v = v;
            productionDatas = new List<ProductionDataClass>();
            FormatData();
        }

        public List<ProductionDataClass> productionDatas { get; internal set; }

        private void FormatData()
        {
            string[] _data = v.Split(';');
            foreach (string _str in _data)
            {
                ProductionDataClass _productionData = new ProductionDataClass();
                if ((_str != null) && (_str != string.Empty))
                {
                    //config, finishedQty, okQty, ngQty, repairedQty
                    string[] _item = _str.Split(':');
                    if (_item.Length >= 6)
                    {
                        _productionData.config = _item[0];

                        bool _v = int.TryParse(_item[1], out _productionData.finishedQty);
                        _v = int.TryParse(_item[2], out _productionData.okQty);
                        _v = int.TryParse(_item[3], out _productionData.ngQty);
                        _v = int.TryParse(_item[4], out _productionData.repairedQty);
                        _v = int.TryParse(_item[5], out _productionData.reportYield);
                        productionDatas.Add(_productionData);
                    }
                }
            }
        }
    }
}
